package com.example.weddingapp.adapter;

import android.content.Context;

import com.example.weddingapp.R;
import com.example.weddingapp.base.binding.BaseBindingAdapter;
import com.example.weddingapp.base.binding.BaseBindingHolder;
import com.example.weddingapp.databinding.ItemGiftBinding;
import com.example.weddingapp.utils.CommonUtil;
import com.example.weddingapp.utils.ImageLoaderUtil;

import cn.leancloud.AVFile;
import cn.leancloud.AVObject;

public class GiftAdapter extends BaseBindingAdapter<AVObject, ItemGiftBinding> {
    private Context mContext;

    public GiftAdapter(Context context) {
        super(R.layout.item_gift);
        this.mContext = context;
    }

    @Override
    protected void bindView(BaseBindingHolder holder, AVObject bean, ItemGiftBinding binding, int position) {
        binding.tvDate.setText(CommonUtil.parseDate(bean.getCreatedAt()));
        AVObject fromUser = bean.getAVObject("fromUser");
        String nick = fromUser.getString("nick");
        binding.tvName.setText(nick);

        binding.tvType.setText("送礼");
        Double value = Double.valueOf(bean.getInt("intMoney")) / 100;
        String money = CommonUtil.formatAmount(value);
        binding.tvMoney.setText("+" + money);


        AVFile headImg = fromUser.getAVFile("headImg");
        if (headImg != null)
            ImageLoaderUtil.displayHeadImage(mContext, headImg.getUrl(), binding.ivIcon);

    }
}
